import React, { Component } from 'react'
import echarts from 'echarts';
import { getFindAll } from '@/utils/api/api'
import moment from 'moment';
export default class componentName extends Component {
  state = {
    timeArr: []
  }
  render() {
    return (
      <div>
        echarts
        <div id="main" style={{ height: '600px' }}></div>
      </div>
    )
  }

  componentDidMount() {
    this.getBlogslist()
  }

  async getBlogslist() {
    let data = await getFindAll()
    let list = data.data;
    let arr = []
    list.forEach((item, index) => {
      arr.push(moment(item.createTime).format('YYYY-MM-DD'))
      this.setState({
        timeArr: arr
      })
    })
    this.myEcharts()
    console.log(this.state.timeArr, 'titmearrr----')
  }

  myEcharts() {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    // 绘制图表
    myChart.setOption({
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      xAxis: {
        data: this.state.timeArr
      },
      yAxis: {},
      series: [{
        name: '销量',
        type: 'bar',
        data: [5, 20, 36, 10, 10, 20]
      }]
    });
  }
}
